import type { RouteLocationNormalized } from "vue-router";

//全局中间件
export default defineNuxtRouteMiddleware(
  ({ path }: RouteLocationNormalized, from: RouteLocationNormalized) => {
    let token = useCookie("token");
    const router = useRouter();
    const greenPassageway = ["/", "/login", "/register", "/error"];
    const result = greenPassageway.find((item) => item == path);
    if (!result && !token.value) router.push("/error");
    if (path == "/") {
      return router.resolve("/login");
    }
    if (path == "/main") {
      return router.resolve("/main/message");
    }
  }
);
